<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            class="input-with-select"
            v-model="queryInfo.query"
            clearable
          >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表单区 -->
      <el-table :data="orderlist" style="width: 100%" stripe border>
        <el-table-column type="index"></el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="500"
        ></el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="80"
        ></el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="80">
          <template v-slot="scope">
            <el-tag type="danger" v-if="scope.row.pay_status === 0"
              >未付款</el-tag
            >
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="80">
        </el-table-column>
        <el-table-column label="下单时间">
          <template v-slot="scope">
            {{ scope.row.create_time | dataFormate("YYY-MM-DD HH:mm:ss") }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              size="mini"
              class="el-icon-edit"
              @click="showEditDialog"
            ></el-button>
            <el-button
              type="success"
              size="mini"
              class="el-icon-location"
               @click="showMsgInfo"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
      <!-- 修改地址 -->
      <el-dialog
        title="修改地址"
        :visible.sync="editAddressVisible"
        width="50%"
        @close="editDialogClosed"
      >
        <el-form
          ref="editAddressRef"
          :rules="editAddressRules"
          :model="editform"
          label-width="80px"
        >
          <el-form-item label="省市区/县" prop="address">
            <el-cascader
              v-model="cityArr"
              :options="citydata"
              :props="cityProps"
              @change="handleChange"
            ></el-cascader>
            <!-- <el-input v-model="editform.address"></el-input> -->
          </el-form-item>
          <el-form-item label="详细地址" prop="addressInfo">
            <el-input v-model="editform.addressInfo"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editAddressVisible = false">取 消</el-button>
          <el-button type="primary" @click="editAddressVisible=false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 查看物流信息对话框 -->
      <el-dialog
        title="查看物流信息"
        :visible.sync="progressVisible"
        width="50%"
      >
        <el-timeline>
          <el-timeline-item
            v-for="(item, i) in progress"
            :key="i"
            :timestamp="item.ftime"
            icon="el-icon-more"
            color="pink"
          >
            {{ item.context }}
          </el-timeline-item>
        </el-timeline>
        <span slot="footer" class="dialog-footer">
          <el-button @click="progressVisible = false">取 消</el-button>
          <el-button type="primary" @click="progressVisible=false">确 定</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>
          

<script>
import citydata from "../../citydata";
export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      //   商品列表的数组
      orderlist: [],
      // 总数
      total: 0,
      //   修改地址对话框的布尔值
      editAddressVisible: false,
      editform: {
        address: "",
        addressInfo: "",
      },
      editAddressRules: {
        address: [
          { required: true, message: "请选择省市区/县", trigger: "blur" },
        ],
        addressInfo: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      // 挂载数据
      citydata,
      // 级联选择框的配置信息
      cityProps: {
        //   触发状态
        expandTrigger: "hover",
        //   父子关联节点
        children: "children",
        //   提交给后台的id
        value: "value",
        //   给用户看到的数据
        label: "label",
      },
      cityArr: [],
      // 控制物流信息的对话框的物流值
      progressVisible: false,
      // 储存信息的数据
      progress: [],
    };
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo,
      });
      if (res.meta.status !== 200) {
        return this.$message.error("获取商品列表信息失败");
      }
      this.orderlist = res.data.goods;
      this.total = res.data.total;
    },
    // pagsize发生变化触发的发
    handleSizeChange(newV) {
      this.queryInfo.pagesize = newV;
      // 重新发送请求
      this.getOrderList();
    },
    // pagsnum发生变化触发的发
    handleCurrentChange(newV) {
      this.queryInfo.pagenum = newV;
      // 重新发生请求
      this.getOrderList();
    },
    // 修改对话框
    showEditDialog() {
      this.editAddressVisible = true;
    },
    // 监听对话框的关闭事件，表单
    editDialogClosed() {
      this.$refs.editAddressRef.resetFields();
    },
    handleChange() {
      console.log(this.cityArr);
    },
    // showorderesDialog(){
    //     this.editAddressVisible=true
    // },

    // 展示物流信息
    async showMsgInfo() {
      const { data: res } = await this.$http.get(`/kuaidi/1106975712662`);
      // console.log(res);
      if (res.meta.status != 200) {
        return this.$message.error("获取物流信息失败,请稍后重试");
      }
      this.progress = res.data;
      this.progressVisible = true;
    },
  },

  created() {
    this.getOrderList();
  },
};
</script>

<style>
</style>